﻿using MediatR;
using S.PurchaseAndSales.Read.Api.Application.Command.SheepSaleCommand;
using S.PurchaseAndSales.Read.Api.Dto;
using S.PurchaseAndSales.Infrastructure.Interface.SalesForm;
using S.PurchaseAndSales.Domain.Model;

namespace S.PurchaseAndSales.Read.Api.Application.CommandHandlers.SheepSaleHandler
{
    public class GetClientListHandler : IRequestHandler<GetClientListCommand, List<ClientDto>>
    {

        private readonly ICustomerRepository customer;

        public GetClientListHandler(ICustomerRepository customer)
        {
            this.customer = customer;
        }

        public async Task<List<ClientDto>> Handle(GetClientListCommand request, CancellationToken cancellationToken)
        {
            //获取到客户信息
            List<CustomerInformationModel> childList = customer.GetAllAsync().Result;
            //将Id与客户名称赋值
            List<ClientDto> children = childList.Select(x => new ClientDto
            {
                Value = x.CustomerInformationId,
                Label = x.CustomerName,
            }).ToList();

            return children;
        }
    }
}
